/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.ui.components;

import com.bff.bjj.ui.component.MusicListCellRenderer;
import com.bff.bjj.ui.component.ColorProperties;
import java.awt.Component;
import java.util.HashMap;
import javax.swing.JList;
import org.bff.slimserver.musicobjects.SlimGenre;

/**
 *
 * @author bfindeisen
 */
public class GenreListCellRenderer extends MusicListCellRenderer {

    private HashMap<SlimGenre, GenreCellPanelIface> genrePanels;

    public GenreListCellRenderer() {
        super();
        genrePanels = new HashMap<SlimGenre, GenreCellPanelIface>();
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        GenreCellPanelIface panel = null;
        if (value instanceof SlimGenre) {
            SlimGenre genre = (SlimGenre) value;
            panel = genrePanels.get(genre);

            if (panel == null) {
                panel = new GenreCellPanel(genre, list);
                genrePanels.put(genre, panel);
            }
        }

        if (panel != null) {
            if ((index % 2) == 0) {
                panel.setEven();
            } else {
                panel.setOdd();
            }

            if (!isSelected) {
                panel.setForeground(ColorProperties.LIST_FOREGROUND);
                panel.setNotSelected();
            } else {
                panel.setSelected();
            }
        }

        return panel.getPanel();

    }
}
